<template>
  <div class="employees-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <login-setting
              :user-detail="userDetail"
              @updateEmpDetailEV="updateFn"
            />
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <user-info
              ref="userInfo"
              @updateUserInfoEV="updateUserInfoFn"
            />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <job-info />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import loginSetting from './components/login-setting.vue'
import userInfo from './components/user-info.vue'
import jobInfo from './components/job-info.vue'
import { getUserDetailByIdAPI, saveUserDetailByIdAPI } from '@/api/employees'
export default {
  name: 'EmployeesDetail',
  components: {
    loginSetting,
    userInfo,
    jobInfo
  },
  data() {
    return {
      userDetail: {}// 员工详情
    }
  },
  created() {
    this.getUserDetailFn()
  },
  methods: {
    // 获取-员工详情
    async getUserDetailFn() {
      const res = await getUserDetailByIdAPI(this.$route.query.id)
      console.log(res)
      // 方式1: 直接给子组件data赋值
      // 组织架构: 直接给子组件data赋值
      // this.$refs.别名拿到子组件对象.内部data名字直接赋值
      this.$refs.userInfo.userInfo = res.data
      // 方式2: 传统的方式, 父->子 (然后子里把props的值赋予给data)
      this.userDetail = res.data
    },
    // 更新-员工详情(姓名/密码)
    async updateFn(dataObj) {
      const res = await saveUserDetailByIdAPI(dataObj)
      this.getUserDetailFn() // 重新获取一次详情数据->再次回显(有点多余)
      this.$message.success(res.message)
    },
    // 更新-员工详情(工号/其他...)
    async updateUserInfoFn(dataObj) {
      const res = await saveUserDetailByIdAPI(dataObj)
      this.getUserDetailFn() // 重新获取一次详情数据->再次回显(有点多余)
      this.$message.success(res.message)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
